import {
  DagreLayout
} from '@antv/layout'
var trigger_right = require('@/views/main/projects/imgs/right.png')
var trigger_left = require('@/views/main/projects/imgs/left.png')
var trigger_center = require('@/views/main/projects/imgs/center.png')

var floorHight = 40


export default {
  formDataFixed({
    list,
    trigger
  }) {
    let center = 417
    let step = 16
    let data = {
      nodes: [{
        id: "mount",
        shape: 'image',
        x: center - 48,
        y: 0,
        attrs: {
          info: {
            initX: center - 48,
            initY: 0,
            ShearerLoc: 50
          }
        },
        width: 100,
        height: 45,
        imageUrl: trigger == 1 ? trigger_left : trigger == 2 ? trigger_right : trigger_center,
      }],
      edges: []
    }
    let nodes = list.map((item, i) => {
      let x = item.ActRegionL * step
      let width = Math.abs(item.ActRegionH - item.ActRegionL) * step
      let y = item.hierarchy * 50
      let obj = {
        id: item.STrackID,
        shape: 'rect',
        width: width,
        height: 40,
        x: x,
        y: y,
        attrs: {
          info: {
            initX: x,
            initY: y,
            ...item
          },
          body: {
            fill: item.color,
            stroke: 'transparent',
          },
          label: {
            fill: '#000',
            text: item.name,
          },
        },
        tools: [{
          name: 'button-remove',
          args: {
            x: '100%',
            y: 0,
            offset: {
              x: -10,
              y: 10
            },
          },
        }, ],
      }
      return obj
    })
    // let nodes = list.map((item, i) => {
    //   let x = item.ActRegionL * step
    //   let width = Math.abs(item.ActRegionH - item.ActRegionL) * step
    //   let y = item.hierarchy * 50
    //   let obj = {
    //     id: item.STrackID,
    //     shape: 'rect',
    //     width: width,
    //     height: 40,
    //     x: x,
    //     y: y,
    //     attrs: {
    //       info: {
    //         initX: x,
    //         initY: y,
    //         ...item
    //       },
    //       body: {
    //         fill: item.color,
    //         stroke: 'transparent',
    //       },
    //       label: {
    //         fill: '#000',
    //         text: item.name,
    //       },
    //     },
    //     tools: [{
    //       name: 'button-remove',
    //       args: {
    //         x: '100%',
    //         y: 0,
    //         offset: {
    //           x: -10,
    //           y: 10
    //         },
    //       },
    //     }, ],
    //   }
    //   return obj
    // })
    let edges = list.map(item => {
      let obj = {
        source: item.PreRunnerID,
        target: item.STrackID,
        router: {
          // name:  item.ShearerDir == 0 ? 'orth' : "normal",
          name: "orth"
          // args: {
          //   padding: 10,
          // },
        },
        attrs: {
          line: {
            stroke: item.ShearerDir == 0 ? '#fd6d6f' : '#000000',
            strokeWidth: 1,
          },
        },
      }
      return obj
    })
    data.nodes = [
      ...data.nodes,
      ...nodes
    ]
    data.edges = [
      ...edges
    ]
    return data

  },
  formDataFollow(list, node, trigger) {
    let center = document.getElementById(node || "followMount").scrollWidth / 2
    let data = {
      nodes: [{
        id: "mount",
        shape: 'image',
        x: center - 50,
        y: 0,
        attrs: {
          info: {
            initX: center - 50,
            initY: 0
          }
        },
        width: 100,
        height: 45,
        imageUrl: trigger == 1 ? trigger_left : trigger == 2 ? trigger_right : trigger_center,
      }]
    }
    let step = 1
    let nodes = []
    nodes = list.map(item => {
      let x = 0
      if (!item.hasOwnProperty('_SDLength') || !item.hasOwnProperty('_SDScope')) {
        item._SDScope = 0
        item._SDLength = 0
      }
      if (trigger == 1) {
        if (item.ShearerDir == 2) {
          x = center - (item.ShearerLoc * 1 + item._SDLength * 1 + item._SDScope * 1) * step
        }
        if (item.ShearerDir == 1) {
          x = center + (item.ShearerLoc * 1 + item._SDLength * 1) * step
        }
      }
      if (trigger == 2) {
        if (item.ShearerDir == 1) {
          x = center - (item.ShearerLoc * 1 + item._SDLength * 1 + item._SDScope * 1) * step
        }
        if (item.ShearerDir == 2) {
          x = center + (item.ShearerLoc * 1 + item._SDLength * 1) * step
        }
      }
      let obj = {
        id: item.STrackID,
        shape: 'rect',
        width: Math.abs(item._SDScope * 1 - item._SDLength * 1),
        height: 40,
        x: x,
        y: 60,
        attrs: {
          info: {
            ...item
          },
          info: {
            initX: x,
            initY: 60
          },
          body: {
            fill: item.color,
            stroke: 'transparent',
          },
          label: {
            fill: '#000',
            text: item.name,
            fontSize: 12,
          },
        },
      }
      return obj
    })
    data.nodes = [
      ...data.nodes,
      ...nodes
    ]
    // console.log(data);
    return data
  },
  formDataMount(list) {
    let data = {
      nodes: []
    }
    let step = 5;
    data.nodes = list.map((item, i) => {
      let obj = {
        id: item.STrackID,
        shape: 'rect',
        width: (item.ActRegionH - item.ActRegionL) * step,
        height: 40,
        x: item.ActRegionL * 1 * step,
        y: i * 50,
        attrs: {
          info: {
            ...item
          },
          info: {
            initX: item.ActRegionL * 1 * step,
            initY: i * 50
          },
          body: {
            fill: item.color,
            stroke: 'transparent',
            rx: 20,
            ry: 20
          },
          label: {
            fill: '#000',
            text: item.name
          },
        },
      }
      return obj
    })
    return data
  }
}
